package com.xbts.system.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.xbts.system.domain.dto.InsertMaterialToTemplateDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.Data;
import com.xbts.common.annotation.Excel;
import com.xbts.common.utils.StringUtils;
import com.xbts.common.core.domain.BaseEntity;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Objects;

/**
 * 模板对象 sei_template
 *
 * @author xbts
 * @date 2023-08-23
 */
@Data
@ApiModel("模板对象")
@TableName("sei_template")
public class SeiTemplate extends BaseEntity {

    private static final long serialVersionUID=1L;

    /** 模板Id */
    @TableId
    private String templateId;

    /** 隶属人员 */
    @Excel(name = "隶属人员")
    @ApiModelProperty("隶属人员")
    private String affiliationName;

    /** 父级id */
    @Excel(name = "父级id")
    @ApiModelProperty("父级id")
    private String parentId;

    /** 父级名称 */
    @Excel(name = "父级名称")
    @ApiModelProperty("父级名称")
    @TableField(exist = false)
    private String parentName;

    /** 名称 */
    @Excel(name = "名称")
    @ApiModelProperty("名称")
    @NotEmpty
    private String name;

    /** 模板 */
    @Excel(name = "模板")
    @ApiModelProperty("模板")
    private String template;

    /** 模板 */
    @Excel(name = "模板")
    @ApiModelProperty("模板")
    private String materialList;

    /** 模板类型id */
    @ApiModelProperty("模板类型id")
    private String templateTypeId;

    /** 模板名称 */
    @ApiModelProperty("模板类型名称")
    private String templateTypeName;

    /** 素材树 */
    @ApiModelProperty("素材树")
    @TableField(exist = false)
    private List<SeiMaterial> materialTree;

    @TableField(exist = false)
    private InsertMaterialToTemplateDto materialToTemplateDto;

    public<T> QueryWrapper<T> queryWrapper(){
        QueryWrapper<T> queryWrapper=new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(name),"t.name",name);
        queryWrapper.eq(Objects.nonNull(templateTypeId),"t.template_type_id",templateTypeId);
        queryWrapper.eq(Objects.nonNull(getCreateBy()),"t.create_by",getCreateBy());
        queryWrapper.orderByDesc("t.create_time");
        return queryWrapper;
    }
}